<template>
  <div class="login_wrap">
    <p>老王音乐后台管理系统</p>
    <el-form ref="loginForm" :model="loginForm" label-width="90px">
      <el-form-item label="用户名称：">
        <el-input
          v-model="loginForm.username"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item label="用户密码：">
        <el-input
          v-model="loginForm.password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="btnLogin()">提交</el-button>
        <el-button>重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: 'AkiraMing',
        password: '123456'
      }
    }
  },
  methods: {
    btnLogin: async function() {
      // console.log(this.loginForm)
      var { data: res } = await this.$http.post('api/admin/login', {
        username: this.loginForm.username,
        password: this.loginForm.password
      })
      // console.log(res)
      if (res.msg === '登录成功') {
        console.log('登录成功')
        // console.log(res.token)
        sessionStorage.setItem('token', res.token)
        this.$router.push({ path: '/home' })
      } else {
        console.log('登录失败')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login_wrap {
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  margin: auto;
  padding: 20px 50px;
  width: 300px;
  height: 200px;
  border-radius: 20px;
  box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.1);
  background-color: aliceblue;

  > p {
    font-size: 20px;
    margin-bottom: 10px;
  }
}
</style>
